package com.ihr360.payroll.model.dto.salary.plan.payslip;


import com.ihr360.commons.model.entity.NumberIdWithTimeAndCompanyId;
import com.ihr360.commons.model.meta.table.DynamicCell;
import com.ihr360.payroll.model.dto.salary.embeddable.StaffInfoSnapshot;
import com.ihr360.payroll.model.dto.salary.plan.config.MergedPayslipConfig;
import com.ihr360.payroll.model.dto.salary.plan.config.PayslipConfig;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.Builder;
import lombok.Value;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import java.util.Date;
import java.util.List;

@Builder
@Value
@Entity
@TypeDefs({
        @TypeDef(name = "json", typeClass = JsonStringType.class),
        @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class Payslip extends NumberIdWithTimeAndCompanyId<Long> {

    //: 考虑生成工资单号码

    /** 年份 */
    private int year;

    /** 月份 */
    private int month;

    private int termIndex;

    @ManyToOne(fetch = FetchType.LAZY)
    private PayslipConfig config;

    @ManyToOne(fetch = FetchType.LAZY)
    private MergedPayslipConfig mergedConfig;

    /**
     * 快照信息，会和薪资单重的具体薪资内容有重复
     */
    private StaffInfoSnapshot staff;

    /**
     * 工资单字段
     */
    @Column(columnDefinition = "text")
    @Type(type="json")
    private List<DynamicCell> fields;

    /** 工资单发布时间 */
    private Date publishedAt;



}